package com.bo.controller;

import com.bo.pojo.Dept;
import com.bo.pojo.Result;
import com.bo.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huangbo
 * @version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list(){
        log.info("部门列表查询1");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }

    @DeleteMapping
    public Result delete(@PathVariable Integer id){
        log.info("删除部门，id={}",id);
        deptService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("添加部门,name={}",dept.getName());
        deptService.add(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result find(@PathVariable Integer id){
        log.info("查找部门，id={}",id);
        Dept dept = deptService.find(id);
        return Result.success(dept);
    }

    @PutMapping
    public Result change(@RequestBody Dept dept){
        log.info("修改部门，参数为id={}, name={}",dept.getId(),dept.getName());
        deptService.change(dept);
        return Result.success();
    }

}
